Imports System.IO

Public MustInherit Class BaseClientPacket
    Implements IDisposable

    Private _b As Byte()
    Private _ms As MemoryStream
    Private _sr As BinaryReader

    Public Sub New(ByVal b As Byte(), ByVal count As Integer)
        Try
            _b = b
            _ms = New MemoryStream(b, 0, count)
            _sr = New BinaryReader(_ms)
        Catch ex As Exception

        End Try
    End Sub

    Public Sub Dispose() Implements System.IDisposable.Dispose
        Try
            _sr.Close()
            _ms.Close()
            _ms.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Public Function ReadInt16() As Int16
        Try
            Return _sr.ReadInt16
        Catch ex As Exception

        End Try
    End Function

    Public Function ReadInt32() As Int32
        Try
            Return _sr.ReadInt32
        Catch ex As Exception

        End Try
    End Function

    Public Function ReadInt64() As Int64
        Try
            Return _sr.ReadInt64
        Catch ex As Exception

        End Try
    End Function

    Public Function ReadByte() As Byte
        Try
            Return _sr.ReadByte
        Catch ex As Exception

        End Try
    End Function

    Public Function ReadBytes(ByVal count As Integer) As Byte()
        Try
            Return _sr.ReadBytes(count)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Public Overrides Function ToString() As String
        Return Me.GetPacketType()
    End Function

    Protected MustOverride Sub RunImpl()
    Public MustOverride Function GetPacketType() As String

End Class
